﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pg.BioMedics.SDR.Diagnostics
{
    /// <summary>
    /// Singleton context for Web performance counters
    /// </summary>
    public sealed class WebPerformanceCounters
    {
        #region Constants

        private const string CategoryName = "SDR Web";

        private const string NumberOfRequestsCounter = "Number of requests";
        private const string AvgRequestSizeCounter = "Average response size";
        private const string AvgResponseSizeCounter = "Average request size";
        private const string AvgResponseTimeCounter = "Average response time";

        #endregion

        #region Fields

        private static WebPerformanceCounters instance;

        private readonly NumberOfItemsPerformanceCounter numberOfRequests = new NumberOfItemsPerformanceCounter(CategoryName, NumberOfRequestsCounter);
        private readonly AverageNumberOfItemsPerformanceCounter avgRequestSize = new AverageNumberOfItemsPerformanceCounter(CategoryName, AvgRequestSizeCounter);
        private readonly AverageNumberOfItemsPerformanceCounter avgResponseSize = new AverageNumberOfItemsPerformanceCounter(CategoryName, AvgResponseSizeCounter);
        private readonly AverageTimingPerformanceCounter avgResponseTime = new AverageTimingPerformanceCounter(CategoryName, AvgResponseTimeCounter);
 
        #endregion

        #region Constructors

        /// <summary>
        /// Creates instance of the observer counters context accessor
        /// </summary>
        private WebPerformanceCounters() { }

        #endregion

        #region Static properties

        /// <summary>
        /// Gets singelton instance of the WebPerformanceCounters class. This
        /// property supports lazy init
        /// </summary>
        public static WebPerformanceCounters Instance
        {
            get
            {
                if (instance == null)
                    instance = new WebPerformanceCounters();

                return instance;
            }
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets number of requests counter
        /// </summary>
        public NumberOfItemsPerformanceCounter NumberOfRequests
        {
            get
            {
                return this.numberOfRequests;
            }
        }

        /// <summary>
        /// Gets Avg request size counter
        /// </summary>
        public AverageNumberOfItemsPerformanceCounter AvgRequestSize
        {
            get
            {
                return this.avgRequestSize;
            }
        }

        /// <summary>
        /// Gets avg response size counter
        /// </summary>
        public AverageNumberOfItemsPerformanceCounter AvgResponseSize
        {
            get
            {
                return this.avgResponseSize;
            }
        }

        /// <summary>
        /// Gets avg response time counter
        /// </summary>
        public AverageTimingPerformanceCounter AvgResponseTime
        {
            get
            {
                return this.avgResponseTime;
            }
        }

        #endregion
    }
}
